import java.util.ArrayList;

public class Gesture 
{
	final String stringDescription;
	ArrayList<Modifier> modifiers;
	
	public Gesture(String description, ArrayList<Modifier> readedModyfiers)
	{
		stringDescription = description;
		modifiers = new ArrayList<Modifier>();
		for (Modifier modifier : readedModyfiers) 
		{
			modifiers.add(modifier);
		}
	}
	
	public boolean equals(Object object)
	{
		Gesture rv = (Gesture)object;
		if(rv == null)
		{
			return false;
		}
		return stringDescription.equals(rv.stringDescription);
	}
	
	/*
	 * @return = setted to true when target were killed
	 * */
	boolean action(Client source, Client target)
	{
		for(int i=0;i<modifiers.size();i++) 
		{
			System.err.println("wykonywanie modifier\n" + modifiers.get(i).toString() + "\nod " + source.connectedPlayer.name + " na " + target.connectedPlayer.name);
			modifiers.get(i).action(source, target);
		}
		if(LoadedAttributes.getInstance().attributes.contains(Attribute.CurrentHitPoints))
		{
			int index = target.connectedPlayer.attributes.lastIndexOf(Attribute.CurrentHitPoints);
			if(index >=0)
			{
				Attribute hitPoints = target.connectedPlayer.attributes.get(index);
				if(hitPoints.value <= 0)
				{
					hitPoints.value = 0;
					return true;
				}
			}
		}
		return false;
	}
	
	public String toString()
	{
		return stringDescription;
	}
	
	public String debug()
	{
		StringBuilder builder = new StringBuilder();
		builder.append(stringDescription);
		for (Modifier modifier : modifiers) 
		{
			builder.append(modifier.toString());
			builder.append("\n");
		}
		return builder.toString();
	}
}